package Gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JPanel;

import Logic.LoginInfo;
import client.LibaryMain;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
/**
 * this class runing the main tra
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class DirectorWindow extends  JPanel {

	/**
	 * this class create the director window 
	 */
	private static final long serialVersionUID = 3180375332028640906L;
	/**
	 * 
	 */

	public static String roll =null;
	/**
	 *  Creates the director window 
	 */
	public DirectorWindow() {
		
		setBackground(new Color(153, 204, 255));
		
		initComponents();
	
	}
	
	
	/**
	 * initilaize  the director window 
	 */
	public void initComponents() {

	
		JButton btnLogout = new JButton("Logout");
		btnLogout.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
		btnLogout.setBounds(666, 604, 84, 25);
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("Logout");
				Arr.add("Worker");
				Arr.add(LoginInfo.UserName);
				LibaryMain.chat.handleMessageFromGui(Arr);
				MainScreen.cardLayot.show(MainScreen.card, "Login");
				
			}
		});
		setLayout(null);
		
		JButton btnRigesterSubscriber = new JButton("Rigester New Subscriber");
		btnRigesterSubscriber.addActionListener(new java.awt.event.ActionListener() {     // Login action listener 
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	btnRigesterSubscriberActionPerformed(evt);
            
            
				
			}
        });
		btnRigesterSubscriber.setBounds(216, 86, 332, 39);
		btnRigesterSubscriber.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		add(btnRigesterSubscriber);
		add(btnLogout);
		
		JButton btnReturnBook = new JButton("Return A Book");
		btnReturnBook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));

		btnReturnBook.setBounds(216, 136, 332, 39);
		add(btnReturnBook);
		btnReturnBook.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	ReturnABookaction(ev);
            					
			}
        });
		JButton btnLending = new JButton("Lending");
		btnLending.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnLending.setBounds(216, 186, 332, 39);
		add(btnLending);
		btnLending.addActionListener(new java.awt.event.ActionListener() {     // View Subscriber Details action listener 
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnLending(ev);
            					
			}
        });
		
		JButton btnViewSubscriberdetails = new JButton("View Subscriber details");
		btnViewSubscriberdetails.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnViewSubscriberdetails.setBounds(216, 236, 332, 39);
		add(btnViewSubscriberdetails);
		
		btnViewSubscriberdetails.addActionListener(new java.awt.event.ActionListener() {     // View Subscriber Details action listener 
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnViewSubscriberDetails(ev);
            					
			}
        });
		
		JButton btnAddBook = new JButton("Add A Book");
	
		btnAddBook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnAddBook.setBounds(216, 286, 332, 39);
		add(btnAddBook);
		btnAddBook.addActionListener(new java.awt.event.ActionListener() {     // add book  action listener 
	        public void actionPerformed(java.awt.event.ActionEvent evt) {
	            btnAddABookActionPerformed(evt);
	        
	        
	                            
	                    }
	    });
		JButton btnRemoveBook = new JButton("Remove Book");
		btnRemoveBook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnRemoveBook.setBounds(216, 336, 332, 39);
		add(btnRemoveBook);
		btnRemoveBook.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnRemoveABook(ev);
            					
			}
        });
		
		JButton btnUpdateBookDetails = new JButton("Update Book Details");
		btnUpdateBookDetails.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnUpdateBookDetails.setBounds(216, 386, 332, 39);
		add(btnUpdateBookDetails);
		btnUpdateBookDetails.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnUpdateBookDetails(ev);
            					
			}
        });
		
		JLabel lblNewLabel = new JLabel("Welcome Director");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 20));
		lblNewLabel.setBounds(12, 13, 289, 16);
		add(lblNewLabel);
		
		JButton btnStatisticalReport = new JButton("Statistical Report");
		btnStatisticalReport.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnStatisticalReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnStatisticalReport(e);
			}
		});
		btnStatisticalReport.setBounds(216, 436, 332, 39);
		add(btnStatisticalReport);
		
		JButton btnWorkers = new JButton("View Workers");
		btnWorkers.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				actionPerformedworker(e);	
			}
		});
		btnWorkers.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnWorkers.setBounds(216, 486, 332, 39);
		add(btnWorkers);
		
		JButton btnFreeze = new JButton("Freeze Subscriber");
		btnFreeze.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnFreeze.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				btnFreeze(arg0);
				
			}
		});
		btnFreeze.setBounds(216, 536, 332, 39);
		add(btnFreeze);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(DirectorWindow.class.getResource("/Gui/images/ob_23c4e9414ac5155a55ff99dbfd008365.png")));
		label.setBounds(387, 74, 501, 519);
		add(label);
		
		JButton btnSearchBook = new JButton("Search Book");
		btnSearchBook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		btnSearchBook.setBounds(216, 592, 332, 39);
		add(btnSearchBook);
		btnSearchBook.addActionListener(new java.awt.event.ActionListener() {     // Login action listener 
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	btnSearchBook(evt);
            
            
				
			}
        });
	

}


	protected void actionPerformedworker(ActionEvent arg0) {
		ArrayList<String> arrr = new ArrayList<String>();
		arrr.add("Workers2");
		LibaryMain.chat.handleMessageFromGui(arrr);		
	}

	protected void btnFreeze(ActionEvent arg0) {
		FreezeSubscriber freeze = new FreezeSubscriber();
		MainScreen.card.add("freeze", freeze);
		MainScreen.cardLayot.show(MainScreen.card, "freeze");		
	}



	protected void btnStatisticalReport(ActionEvent e) {
		ReportsMain report = new ReportsMain();
		MainScreen.card.add("reportmenu", report);
		MainScreen.cardLayot.show(MainScreen.card, "reportmenu");
		
	}



	protected void btnRigesterSubscriberActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		Rigester regdir = new Rigester("DirectorWindow");
		MainScreen.card.add("RigesterDirector", regdir);
		MainScreen.cardLayot.show(MainScreen.card, "RigesterDirector");
	
	}
	
	protected void btnAddABookActionPerformed(ActionEvent evt) {
        // TODO Auto-generated method stub
		roll= "DirectorWindow";
		ArrayList<String> Arr=new ArrayList<String>();
        Arr.add("GetCategory");
	    LibaryMain.chat.handleMessageFromGui(Arr);
	   
	}
	protected void ReturnABookaction(ActionEvent ev) {
		roll= "DirectorWindow";
		ReturnBookgui retb = new ReturnBookgui();
		MainScreen.card.add("returnbook", retb);
		MainScreen.cardLayot.show(MainScreen.card, "returnbook");
		
	}
	protected void btnLending(ActionEvent ev) {
		roll= "DirectorWindow";
		LendingGui lend = new LendingGui();
		MainScreen.card.add("lendBook", lend);
		MainScreen.cardLayot.show(MainScreen.card, "lendBook");
		
	}
	
	public void btnViewSubscriberDetails(ActionEvent e) {
		roll= "DirectorWindow";
		Viewsubscriberdetail view = new Viewsubscriberdetail();
		MainScreen.card.add("viewdetail", view);
		MainScreen.cardLayot.show(MainScreen.card, "viewdetail");
		
	}

	protected void btnRemoveABook(ActionEvent ev) {
		roll= "DirectorWindow";
		RemoveBook rb = new RemoveBook();
		MainScreen.card.add("removebook", rb);
		MainScreen.cardLayot.show(MainScreen.card, "removebook");
		
	}
	protected void btnUpdateBookDetails(ActionEvent ev) {
			roll= "DirectorWindow";
            LibrarianWindow.ubd =  new UpdateBookDetails();
        	MainScreen.card.add("UpdateBook", LibrarianWindow.ubd);
        	MainScreen.cardLayot.show(MainScreen.card, "UpdateBook");
	}
	protected void btnSearchBook(ActionEvent arg0) {
		roll= "DirectorWindow";
		Search sd = new Search();
		MainScreen.card.add("Search", sd);
		MainScreen.cardLayot.show(MainScreen.card, "Search");		
	}
}